package cn.itcast.controller;


import cn.itcast.constant.MessageConstant;
import cn.itcast.entity.Result;
import cn.itcast.pojo.Setmeal;
import cn.itcast.service.SetmealService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmalController {


    @Reference
    private SetmealService setmealService;

    @RequestMapping("/getAllSetmeal")
    public Result getAllSetmeal() {
        List<Setmeal> setmealList = setmealService.getAllSetmeal();

        if (setmealList != null && setmealList.size() > 0) {
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS, setmealList);
        }
        return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
    }

    @RequestMapping("/findCheckgroupAndCheckitemBySetmealId")
    public Result findCheckgroupAndCheckitemBySetmealId(Integer id) {

        Setmeal setmeal = setmealService.findCheckgroupAndCheckitemBySetmealId(id);
        if (setmeal != null) {
            return new Result(true, MessageConstant.QUERY_SETMEAL_FAIL, setmeal);
        }
        return new Result(false, MessageConstant.QUERY_SETMEAL_SUCCESS);
    }


    @RequestMapping("/findById")
    public Result findById(Integer id) {

        Setmeal setmeal = setmealService.findById(id);
        if (setmeal != null) {
            return new Result(true, MessageConstant.GET_JIBENXINXI_FAIL, setmeal);
        }
        return new Result(false, MessageConstant.GET_JIBENXINXI_SUCCESS);
    }
}
